package com.web.service.impl;

import com.web.dao.StudentDAO;
import com.web.dao.impl.StudentDAOImpl;
import com.web.entity.PageVO;
import com.web.entity.Student;
import com.web.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    private StudentDAO studentDAO = new StudentDAOImpl();

    @Override
    public List<Student> findAllStudents() {
        return studentDAO.selectAllStudents();
    }

    @Override
    public Student selectById(String id) {
        Student stu = studentDAO.selectById(id);
        return stu;
    }

    @Override
    public List<Student> selectByKeyWord(String keyword) {
        List<Student> stus = studentDAO.selectByKeyWord(keyword);
        return stus;
    }


    @Override
    public void addStudent(String name, String age,String cellphone,String address,String gender) {
        studentDAO.addStudent(name,age,cellphone,address,gender);
    }


    @Override
    public void updateStudent(String name, String age,String cellphone,String address,String gender,String id) {
        studentDAO.updateStudent(name,age,cellphone,address,gender,id);
    }


    @Override
    public void deleteStudent(String id) {
        studentDAO.deleteStudent(id);
    }


    @Override
    public PageVO findStudentPage(int current, int pageSize) {
        //查询学生总数
        int count = studentDAO.selectStudentCount();
        //获得查询的行数
        int start = (current - 1) * pageSize;
        //分页查询学生集合
        List<Student> students = studentDAO.selectStudentPage(start,pageSize);
        return new PageVO(current,pageSize,count,students);
    }
}